package com.guet.news_main.controller;

import com.guet.common.utils.R;
import com.guet.news_main.entity.NewsArticle;
import com.guet.news_main.service.NewsArticleService;
import com.guet.news_main.util.RedisUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname DailyRecommendationController
 * @Description TODO
 * @Date 2022/1/6 11:59
 * @Author csp
 */
@RestController
@RequestMapping("dailyRecommendation")
@CrossOrigin
public class DailyRecommendationController {
    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private NewsArticleService newsArticleService;


    @ApiOperation(value = "模拟给用户推送新闻")
    @PostMapping("push/{id}")
    private R PushDailyRecommendation(@PathVariable String id){
        NewsArticle push = newsArticleService.getById(id);
        rabbitTemplate.convertAndSend("boot_topic_exchange","boot.haha",push);
        return R.ok();
    }

    @GetMapping("get")
    public R GetDailyRecommendation(){
        List<Object> newsList = redisUtil.lGet("newsList", 0, -1);
        return R.ok().data("DailyList",newsList);
    }
}